Given an
integer n. Print “Ok” if n consists of a single
digit, and “No” otherwise.
Input. One integer n
(|n| ≤ 109).
Output. Print “Ok” if n is
a single-digit number, and “No” otherwise.
Sample input 1 |
Sample output 1 |
7 |
Ok |
|
|
Sample input 2 |
Sample output 2 |
-77 |
No |
conditional
statement
The input
number n can be negative. The absolute value of n consists of a single digit. In other words, the
inequality -9 ≤ n ≤ 9 must
hold.
Algorithm implementation
Read the input value of n.
scanf("%d", &n);
Print the answer.
if (n > -10 && n < 10) puts("Ok");
else puts("No");
Java implementation
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int n = con.nextInt();
if (n > -10
&& n < 10) System.out.println("Ok");
else System.out.println("No");
con.close();
}
}
Python implementation
Read the input value of n.
n = int(input())
Print the answer.
if n > -10 and n < 10: print("Ok")
else: print("No")
Python implementation – 2
Read the input value of n.
n = int(input())
Print the answer.
if -10 < n < 10: print("Ok")
else: print("No")